package com.changhong.wlyspectrum.HttpUtil;

import android.app.DownloadManager;

import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;

import java.io.IOException;
import java.net.CookieManager;
import java.net.CookiePolicy;

/**
 * Created by wyd on 2017/9/1.
 */

public class HttpFunc {
    private static HttpFunc instance;
    private static final String SEVER_ADDR = "http://10.9.51.45";
    private static final String KEY = "";
    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    public static final String RESPONSE_SUCCESS = "200";   //请求成功
    public static final String RESPONSE_FAILED = "400";   //请求异常
    //public static final String RESPONSE_SUCCESS = "200";   //请求成功
    //public static final String RESPONSE_SUCCESS = "200";   //请求成功
    private OkHttpClient httpClient;
    private HttpFunc(){
        httpClient = new OkHttpClient();
        httpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
    }

    public  static HttpFunc getInstance(){
        if(instance == null){
            instance = new HttpFunc();
        }
        return instance;
    }

    public  Response GetResponse(String url , String js) throws IOException{
        RequestBody body = RequestBody.create(JSON,js);
        Request request = new Request.Builder()
                .url(SEVER_ADDR + url)
                .post(body)
                .build();
        Response response =  httpClient.newCall(request).execute();
        return response;
     }
}
